package spatialmarketplace.cem.action;

import java.util.ArrayList;
import java.util.List;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.util.Log;
import net.sourceforge.stripes.validation.SimpleError;
import net.sourceforge.stripes.validation.ValidationError;
import spatialmarketplace.cem.model.Group;

public class GroupListActionBean extends GroupActionBean {

    private static final Log logger = Log.getInstance(GroupListActionBean.class);
    private static final String LIST = "/WEB-INF/jsp/group_list.jsp";
    List<Group> myGroups = new ArrayList<Group>();

    @DefaultHandler
    public Resolution list() {
        String myCurrentUserId = getContext().getRequest().getParameter("currentUID");
        System.out.println("fffff " + myCurrentUserId);
        return new ForwardResolution(LIST);
    }

    public void setMyGroups(List<Group> myGroups) {
        this.myGroups = myGroups;
    }

    /*
     * method to get all my groups
     */
    public List<Group> getMyGroups() {
        Integer userId = 2;
        // List<Group> myGroups=new ArrayList<Group>();
        try {
            myGroups = getGroupDao().getMyGroups(userId);

        } catch (Exception e) {
            ValidationError error = new SimpleError(myGroups + " The list of group cannot be displayed.");
            getContext().getValidationErrors().add("myGroups", error);
            logger.error("Error" + e);
            System.out.println("Error: " + WelcomeScreenActionBean.class.getName() + ", " + e);
        }

        return myGroups;
    }
}
